<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('target_index')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <target-index-modal ref="modalForm" @ok="modalFormOk"></target-index-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import TargetIndexModal from './modules/TargetIndexModal'

  export default {
    name: 'TargetIndexList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      TargetIndexModal
    },
    data () {
      return {
        description: 'target_index管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'品类',
            align:"center",
            dataIndex: 'targetType'
          },
          {
            title:'名称',
            align:"center",
            dataIndex: 'targetName'
          },
          {
            title:'品种',
            align:"center",
            dataIndex: 'tradevariety'
          },
          {
            title:'开仓趋势',
            align:"center",
            dataIndex: 'opentrendkind'
          },
          {
            title:'开仓类型1：多单； 2：空单； 3：不限类型',
            align:"center",
            dataIndex: 'openkind'
          },
          {
            title:'同一趋势下只开仓一次',
            align:"center",
            dataIndex: 'openonlyone'
          },
          {
            title:'开仓固定手数',
            align:"center",
            dataIndex: 'fixedlots'
          },
          {
            title:'开仓自动手数',
            align:"center",
            dataIndex: 'isautolots'
          },
          {
            title:'开仓手数自动计算比率（手/万$）',
            align:"center",
            dataIndex: 'lotsrates'
          },
          {
            title:'DMI趋势启动点',
            align:"center",
            dataIndex: 'dmia'
          },
          {
            title:'DMI趋势启动结束点',
            align:"center",
            dataIndex: 'dmib'
          },
          {
            title:'多方RSI区间小值',
            align:"center",
            dataIndex: 'longrsia'
          },
          {
            title:'多方RSI区间大值',
            align:"center",
            dataIndex: 'longrsib'
          },
          {
            title:'空方RSI区间小值',
            align:"center",
            dataIndex: 'shortrsia'
          },
          {
            title:'空方RSI区间大值',
            align:"center",
            dataIndex: 'shortrsib'
          },
          {
            title:'允许CCI',
            align:"center",
            dataIndex: 'usecci'
          },
          {
            title:'多单CCI阀值',
            align:"center",
            dataIndex: 'longccilevel'
          },
          {
            title:'多单CCI差值（>0）',
            align:"center",
            dataIndex: 'longccideviation'
          },
          {
            title:'空单CCI阀值',
            align:"center",
            dataIndex: 'shortccilevel'
          },
          {
            title:'空单CCI差值（>0）',
            align:"center",
            dataIndex: 'shortccideviation'
          },
          {
            title:'止损点数',
            align:"center",
            dataIndex: 'stoploss'
          },
          {
            title:'动态止损点（波动率）',
            align:"center",
            dataIndex: 'useautostoploss'
          },
          {
            title:'止盈点数',
            align:"center",
            dataIndex: 'takeprofit'
          },
          {
            title:'移损点数',
            align:"center",
            dataIndex: 'movesl'
          },
          {
            title:'移盈点数',
            align:"center",
            dataIndex: 'movetp'
          },
          {
            title:'移损移盈时利润优先',
            align:"center",
            dataIndex: 'profitfirstonmovesp'
          },
          {
            title:'RSI超买值',
            align:"center",
            dataIndex: 'rsioverbought'
          },
          {
            title:'RSI超卖值',
            align:"center",
            dataIndex: 'rsioversold'
          },
          {
            title:'持仓趋势反转平仓',
            align:"center",
            dataIndex: 'atxtrendrevers'
          },
          {
            title:'EMA反转平仓',
            align:"center",
            dataIndex: 'ematrendrevers'
          },
          {
            title:'强趋势变弱平仓',
            align:"center",
            dataIndex: 'dmistrong2weak'
          },
          {
            title:'三色趋势反转平仓',
            align:"center",
            dataIndex: 'trendrevers3'
          },
          {
            title:'三色趋势共振',
            align:"center",
            dataIndex: 'same3trend'
          },
          {
            title:'持仓趋势共振',
            align:"center",
            dataIndex: 'sameatxtrend'
          },
          {
            title:'DMI趋势逐渐增强',
            align:"center",
            dataIndex: 'samestrongdmi'
          },
          {
            title:'DMI趋势须比较K线柱数',
            align:"center",
            dataIndex: 'samestrongdminums'
          },
          {
            title:'DMI趋势差值',
            align:"center",
            dataIndex: 'samestrongdmideviation'
          },
          {
            title:'EMA同方向开仓',
            align:"center",
            dataIndex: 'sameema'
          },
          {
            title:'EMA同向时突破或跌破EMA线的K线柱数',
            align:"center",
            dataIndex: 'sameemanums'
          },
          {
            title:'K线柱走势同向',
            align:"center",
            dataIndex: 'samek'
          },
          {
            title:'比较K线柱数（值为2或3或4）',
            align:"center",
            dataIndex: 'sameknums'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/gongqiang/targetIndex/list",
          delete: "/gongqiang/targetIndex/delete",
          deleteBatch: "/gongqiang/targetIndex/deleteBatch",
          exportXlsUrl: "/gongqiang/targetIndex/exportXls",
          importExcelUrl: "gongqiang/targetIndex/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'targetType',text:'品类'})
        fieldList.push({type:'string',value:'targetName',text:'名称'})
        fieldList.push({type:'string',value:'tradevariety',text:'品种'})
        fieldList.push({type:'int',value:'opentrendkind',text:'开仓趋势'})
        fieldList.push({type:'int',value:'openkind',text:'开仓类型1：多单； 2：空单； 3：不限类型'})
        fieldList.push({type:'int',value:'openonlyone',text:'同一趋势下只开仓一次'})
        fieldList.push({type:'number',value:'fixedlots',text:'开仓固定手数'})
        fieldList.push({type:'int',value:'isautolots',text:'开仓自动手数'})
        fieldList.push({type:'number',value:'lotsrates',text:'开仓手数自动计算比率（手/万$）'})
        fieldList.push({type:'number',value:'dmia',text:'DMI趋势启动点'})
        fieldList.push({type:'number',value:'dmib',text:'DMI趋势启动结束点'})
        fieldList.push({type:'number',value:'longrsia',text:'多方RSI区间小值'})
        fieldList.push({type:'number',value:'longrsib',text:'多方RSI区间大值'})
        fieldList.push({type:'number',value:'shortrsia',text:'空方RSI区间小值'})
        fieldList.push({type:'number',value:'shortrsib',text:'空方RSI区间大值'})
        fieldList.push({type:'int',value:'usecci',text:'允许CCI'})
        fieldList.push({type:'number',value:'longccilevel',text:'多单CCI阀值'})
        fieldList.push({type:'number',value:'longccideviation',text:'多单CCI差值（>0）'})
        fieldList.push({type:'number',value:'shortccilevel',text:'空单CCI阀值'})
        fieldList.push({type:'number',value:'shortccideviation',text:'空单CCI差值（>0）'})
        fieldList.push({type:'int',value:'stoploss',text:'止损点数'})
        fieldList.push({type:'int',value:'useautostoploss',text:'动态止损点（波动率）'})
        fieldList.push({type:'int',value:'takeprofit',text:'止盈点数'})
        fieldList.push({type:'int',value:'movesl',text:'移损点数'})
        fieldList.push({type:'int',value:'movetp',text:'移盈点数'})
        fieldList.push({type:'int',value:'profitfirstonmovesp',text:'移损移盈时利润优先'})
        fieldList.push({type:'number',value:'rsioverbought',text:'RSI超买值'})
        fieldList.push({type:'number',value:'rsioversold',text:'RSI超卖值'})
        fieldList.push({type:'int',value:'atxtrendrevers',text:'持仓趋势反转平仓'})
        fieldList.push({type:'int',value:'ematrendrevers',text:'EMA反转平仓'})
        fieldList.push({type:'int',value:'dmistrong2weak',text:'强趋势变弱平仓'})
        fieldList.push({type:'int',value:'trendrevers3',text:'三色趋势反转平仓'})
        fieldList.push({type:'int',value:'same3trend',text:'三色趋势共振'})
        fieldList.push({type:'int',value:'sameatxtrend',text:'持仓趋势共振'})
        fieldList.push({type:'int',value:'samestrongdmi',text:'DMI趋势逐渐增强'})
        fieldList.push({type:'int',value:'samestrongdminums',text:'DMI趋势须比较K线柱数'})
        fieldList.push({type:'number',value:'samestrongdmideviation',text:'DMI趋势差值'})
        fieldList.push({type:'int',value:'sameema',text:'EMA同方向开仓'})
        fieldList.push({type:'int',value:'sameemanums',text:'EMA同向时突破或跌破EMA线的K线柱数'})
        fieldList.push({type:'int',value:'samek',text:'K线柱走势同向'})
        fieldList.push({type:'int',value:'sameknums',text:'比较K线柱数（值为2或3或4）'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>